package com.wjw.demo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class Main2Activity extends AppCompatActivity {
    @BindView(R.id.id_recycler)
    RecyclerView id_recycler;
    private List<String> list;
    private MyAdapter2 myAdapter2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        //黄油刀注册
        ButterKnife.bind(this);
        //设置数据
        initData();
        //适配器对象
        myAdapter2 = new MyAdapter2(this, list);
        //设置适配器
        id_recycler.setAdapter(myAdapter2);
        //设置布局管理器
        id_recycler.setLayoutManager(new StaggeredGridLayoutManager(
                3, StaggeredGridLayoutManager.VERTICAL));
        //设置条目删除动画
        id_recycler.setItemAnimator(new DefaultItemAnimator());
        //条目点击事件回调
        myAdapter2.setDianji(new Dianji() {
            @Override
            public void onItemClick(View view, int pos) {
                Toast.makeText(Main2Activity.this, "Click:" + pos, Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onItemLongClick(View view, int pos) {
                myAdapter2.delData(pos);
            }
        });

    }

    private void initData() {
        list = new ArrayList<>();
        for (int i = 'A'; i < 'z'; i++) {
            list.add("" + (char) i);
        }
    }
}
